// createRouter：创建router实例对象
// createWebHistory：创建hash模式的路由

import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/Category/SubCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import Cart from '@/views/Cart/index.vue'
import Order from '@/views/Order/index.vue'
import Pay from '@/views/Pay/index.vue'
import PayCallBack from '@/views/Pay/PayCallBack.vue'
import Member from '@/views/Member/index.vue'
import MyOrder from '@/views/Member/components/MyOrder.vue'
import MyCenter from '@/views/Member/components/MyCenter.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // 配置path和component对应关系
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        {
          // 默认二级路由
          path: '',
          component: Home
        },
        {
          path: 'category/:id',
          component: Category
        },
        {
          path: 'category/sub/:id',
          component: SubCategory
        },
        {
          path: 'detail/:id',
          component: Detail
        },
        {
          path: 'cart',
          component: Cart
        },
        {
          path: 'order',
          component: Order
        },
        {
          path: 'pay',
          component: Pay
        },
        {
          path: 'payCallback',
          component: PayCallBack
        },
        {
          path: 'member',
          component: Member,
          children: [
            { path: '', component: MyCenter},
            { path: 'order', component: MyOrder}
          ]  
        }
      ]
    },
    {
      path: '/login',
      component: Login
    },
  ],
  // 路由滚动行为定制
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
